package java_thinking.unit_8._8_3;

/**
 * @Description : 基类的构造函数中调用了子类中的覆盖方法的案例
 * @author: cww
 * @DateTime: 2019-03-01 21:53
 */

class PolyInitialDemo {
    //7
    public int fatherValue = 5;
    //1
    public static int fatherStaticValue = 15;
    //2 RoundPoly.sunStaticValue = 0!!!
    public static int fatherStaticValue1 = RoundPoly.sunStaticValue;
    void draw(){
        System.out.println("PolyInitialDemo.draw()");
    }
    //6
    PolyInitialDemo(){
        System.out.println("Before PolyInitialDemo.draw()");
        //8
        draw();
        System.out.println("After PolyInitialDemo.draw()");
    }
}

class RoundPoly extends PolyInitialDemo{
    //11
    private int radius = 1;
    //3
    public static int sunStaticValue = 10;
    /**
     * 父类构造器初始化时调用了draw()方法，因为多态性，会调用子类的draw()方法，但是此时
     * 子类还未初始化，给子类的存储空间此时还都是零null；即使是子类的static成员也是在准备状态(0或null)
     * 但是如果在覆盖方法里使用父类的对象成员，那么肯定是已经初始化过了，因为对象成员初始化优先于构造函数
     */
    @Override
    void draw(){
        //9 radius=0
        System.out.println("RoundPoly.draw(), radius="+radius);
        System.out.println("FatherValue="+fatherValue);
        System.out.println("fatherStaticValue="+fatherStaticValue);
        //10 fatherStaticValue1 = 0!!!!
        System.out.println("fatherStaticValue1="+fatherStaticValue1);
    }
    // 5 12
    RoundPoly(int i){
        radius = i;
        System.out.println("RoundPoly(), radius="+radius);
    }
}

class PolyConstructor{
    public static void main(String[] args) {
        //4 13end
        new RoundPoly(3);
    }
}
